package com.myproject.yunPan.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.myproject.yunPan.entity.Backup;
import com.myproject.yunPan.service.BackupTaskService;


@RestController(value = "/backup")
public class HttpCommondController {

    @Autowired
    private BackupTaskService backupTaskService;

    @GetMapping("/getAllTask")
    @ResponseBody
    public List<Backup> getAllTask() {
    	return backupTaskService.getAllTasks();
    }

    @GetMapping("/addTask")
    public void addTask(String localPath, String cloudPath, String time) throws Exception {
        Backup backup = new Backup();
    	backup.setLocalPath(localPath);
    	backup.setCloudPath(cloudPath);
    	backup.setBackupType(0);
    	backup.setMonitor(1);
    	backup.setSync(1);
    	backup.setBackupTime(time);
    	backup.setFileNum(0);
    	backup.setStatus(0);  	
    	backupTaskService.addBackupTask(backup);
    }

    @GetMapping("/deleteTask")
    public void deleteTask(int id) throws Exception {
    	backupTaskService.deleteTask(id);
    }
  
    
}
